// 导入api接口
import { vehicleTimeWarnConfigadd, vehicleTimeWarnConfigdelete, vehicleTimeWarnConfigList, vehicleTimeWarnConfigLists, vehicleTimeWarnConfigupdate } from "@/api/api";
import configJs from '@/utils/configJs';
import { mapGetters, mapState } from 'vuex';
import defaultData from './data';
var data = JSON.parse(JSON.stringify(defaultData))
var adapter = {
	data,
	methods: {
		// ...mapActions(['logOut']),
		/**
		 * 初始化
		 */
		initPage(){
			//还原页面对象
			configJs.revert(data, defaultData);
		},
		initwarntimeList(){
			//获取数据
			vehicleTimeWarnConfigList().then((res)=>{
				console.log(res.data)
				this.page = res.data
			})
		},
		search(val){
			// console.log(this.starttime)
			// console.log(this.endtime)
			let timedata =""
			let params;
			if(this.starttime && this.endtime){
				timedata = this.starttime+"_"+ this.endtime
				console.log(timedata)
			}
			if(typeof val != 'number' && (val = 1)){
				params={
					cph:this.recordSearchObj[0].cph ==''?'':this.recordSearchObj[0].cph,
					jcwbsj:timedata ==''?'':timedata,
					yjxm:this.recordSearchObj[0].yjxm ==''?'':this.recordSearchObj[0].yjxm,
					yjlb:this.recordSearchObj[0].yjlb ==''?'':this.recordSearchObj[0].yjlb,
					yjjg:this.recordSearchObj[0].yjjg ==''?'':this.recordSearchObj[0].yjjg,
					nyr:this.recordSearchObj[0].nyr ==''?'':this.recordSearchObj[0].nyr,
					bz:this.recordSearchObj[0].bz ==''?'':this.recordSearchObj[0].bz
				}
			}else{
				params={
					page:val,
					cph:this.recordSearchObj[0].cph ==''?'':this.recordSearchObj[0].cph,
					jcwbsj:timedata ==''?'':timedata,
					yjxm:this.recordSearchObj[0].yjxm ==''?'':this.recordSearchObj[0].yjxm,
					yjlb:this.recordSearchObj[0].yjlb ==''?'':this.recordSearchObj[0].yjlb,
					yjjg:this.recordSearchObj[0].yjjg ==''?'':this.recordSearchObj[0].yjjg,
					nyr:this.recordSearchObj[0].nyr ==''?'':this.recordSearchObj[0].nyr,
					bz:this.recordSearchObj[0].bz ==''?'':this.recordSearchObj[0].bz
				}
			}
			console.log(params)
			vehicleTimeWarnConfigLists(params).then((res)=>{
				console.log(res)
				this.page = res.data
			})
		},
		reset(){
			this.recordSearchObj = [{
				cph: '',
				jcwbsj: '',
				yjxm: '',
				yjlb: '',
				yjjg: '',
				nyr:'',
				bz: ''
			}]
			this.starttime=""
			this.endtime="",
			this.search()
		},
		save(){
			if(this.editdata.id == ""){
				this.$message({
					type: 'info',
					message: `请进行修改之后在保存`
				});
			}else{
				vehicleTimeWarnConfigupdate(this.editdata).then((res)=>{
					console.log(res)
					if (res.code === 0) {
						this.$message({
							type: 'success',
							message: `修改成功`
						});
						this.editVisi = false
						this.search()
					} else {
						this.$message({
							type: 'info',
							message: `修改失败`
						});
					}
				})
			}
			
		},
		add(){
			this.addVisi = true
			this.addStaff ={
				cph: '',
				jcwbsj: '',
				yjxm: '',
				yjlb: '',
				yjjg: '',
				nyr:'',
				bz: ''
			}
		},
		addClick(){
			console.log(this.adddata[0])
			vehicleTimeWarnConfigadd(this.adddata[0]).then((res)=>{
				console.log(res)
				if (res.code === 0) {
					this.$message({
						type: 'success',
						message: `修改成功`
					});
					this.addVisi = false
					this.search()
				} else {
					this.$message({
						type: 'info',
						message: `修改失败`
					});
				}
			})
		},
		edit(item){
			// console.log(item)
			this.editdata = {...item}
			this.editVisi = true;	
		},

		rowClick(){
			
		},
		deleteClick(id){
			console.log(id)
			let that = this;
			this.$confirm('是否删除该条消息', '删除', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				vehicleTimeWarnConfigdelete(id).then((res)=>{
					// console.log(res)
					that.$message({
						type: 'success',
						message: '删除成功!'
					});
					that.search()
				}) 
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});          
			});
		}
			
	},
	computed: {
		...mapState({
			supperAdmin: state => state.user.supperAdmin,
		}),
		...mapGetters(['userPageAuth']),
	}
}
export default adapter
